package com.zoe.onelink.actuate.feign;

import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2022</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: ruansheng
 * @date: 2022-03-01
 */
@Data
@Accessors(chain = true)
public class FeignClientInfo {

    private String requestMethod;

    private String uri;

    private String methodName;

    private String clientClass;

    private List<Arg> args;

    private String returnType;

    private List<String> exceptions;

    private List<String> annotations;

    public String getSignatureText() {
        StringBuilder sb = new StringBuilder();
        sb.append(this.returnType).append(" ").append(this.methodName).append("(");
        List<String> argNames = this.args.stream().map(Arg::getType).collect(Collectors.toList());
        sb.append(StrUtil.join(",", argNames).replaceAll("[a-zA-Z]+\\.", "")).append(")");
        return sb.toString();
    }

    public String getSignatureCode() {
        return SecureUtil.md5(this.getSignatureText());
    }

    @Data
    @Accessors(chain = true)
    public static class Arg {

        private String name;

        private String type;

        private List<String> annotations;

    }


}
